home *** CD-ROM | disk | FTP | other *** search
/ The 640 MEG Shareware Studio 4 / The 640 Meg Shareware Studio CD-ROM Volume IV (Data Express)(1994).ISO / clang / fhprtsc.zip / FHPRTSC.ASM next >
Assembly Source File  |  1993-05-01  |  12KB  |  389 lines

  1.     PAGE    ,132
  2.     TITLE    HPRTSC
  3.     SUBTTL    Description
  4.  
  5. ; Revision by Bill Reynolds, 10.12.89 
  6. ; Revised version fixes bug which caused the printer to 
  7. ; linefeed incorrectly, resulting in poor printed image, also
  8. ; have (optionally) commented out the code which prompts for
  9. ; which screen page to print, thus causing the program to dump
  10. ; graphics page 1 when PrtSc is pressed and board is in graphics
  11. ; mode. If you would like this function back, just uncomment the
  12. ; lines that are marked X below.
  13.  
  14. ; Copyright (c) 1987, Background Processes
  15. ;
  16. ; Permission is hereby granted to copy, distribute, modify, include,
  17. ; burn, rape, or pillage this software in accordance with the following
  18. ; guidelines:
  19. ;
  20. ;    1) Distribution of this program is to be free. If a charge is made
  21. ;       for copying, it must be no more than $5 US. Permission for
  22. ;       inclusion into commercial products must be obtained individually.
  23. ;
  24. ;    2) Distribution of the program must include this complete source
  25. ;       code, or at least it should be made available. Software
  26. ;       exchange should not only be a way of getting free software,
  27. ;       but should also be a learning experience. The best way to
  28. ;       learn is to be able to read the source code.
  29. ;
  30. ;    3) You promise not to laugh at the code (at least not too hard). I'm
  31. ;       a PDP-11 programmer. If that doesn't mean anything to you, ask
  32. ;       a hacker friend about the advantages of orthogonal instruction sets
  33. ;       and REAL general registers.
  34. ;
  35. ;    4) If you find (or correct - hint, hint) any bugs in this program, I
  36. ;       would appreciate it if you would let me know. This way I can
  37. ;       learn, too.
  38. ;
  39. ; Alan Groupe
  40. ; Background Processes
  41. ; PO Box 6347
  42. ; Nashua, NH 03063-6347
  43.  
  44. ; This program implements a graphics screen dump from a Hercules
  45. ; monochrome graphics board. It is similar to the DOS GRAPHICS.COM in
  46. ; that it takes over the PrtSc interrupt.
  47.  
  48. ; When HPRTSC is typed at the DOS prompt, it grabs the PrtSc interrupt
  49. ; vector, and then issues a terminate and stay resident DOS function
  50. ; call. When the PrtSc key is pressed, this program checks the Hercules
  51. ; board to determine whether it is in text or graphics mode. If the
  52. ; board is in text mode, the program simply executes a far jump to the
  53. ; original PrtSc routine. If the board is in graphics mode, the program
  54. ; waits for a key to be pressed on the keyboard. If the '1' key is pressed,
  55. ; the program scans through the first graphics page (B0000 - B7FFF; called
  56. ; page 0 in the Hercules manual) and formats it for output on the printer.
  57. ; If the '2' key is pressed, the second graphics page (B8000 - BFFFF) is
  58. ; printed. If any other key is pressed, you will hear a short beep and HPRTSC
  59. ; will just return. You can use this to freeze an animated graphics display
  60. ; to look at it more closely. Just press PrtSc to freeze the screen. To
  61. ; unfreeze it, just press any key other than '1' or '2'.
  62. ; The dot mapping of a Hercules board is a little weird. Each byte in
  63. ; the graphics memory corresponds to eight dots horizontally, with the
  64. ; most significant bit of each byte representing the leftmost dot of the
  65. ; eight. There are 720 dots across on the display, so the first 90 bytes
  66. ; (B0000 - B005A) make up the first line on the screen (line 1).
  67. ; However, the next 90 bytes are not line 2, but rather line 5. The next
  68. ; 90 bytes, line 9. This continues down the screen until line 345
  69. ; (B1E3C). The remaining 170 bytes (B1E96 - B1FFF) are unused. Then the
  70. ; 90 byte groups starting at B2000 correspond to lines 2, 6, 10, etc.
  71. ; Therefore, lines 1-10 have the respective starting addresses B0000,
  72. ; B2000, B4000, B6000, B005A, B205A, B405A, B605A, B00B4, and B20B4.
  73. ; This, of course, is not even close to how an Epson printer maps dots
  74. ; on the paper. The Epson printer takes an eight bit byte and prints a
  75. ; column of 8 dots vertically, with the most significant bit at the top.
  76. ; Since the Hercules board is organized horizontally and the Epson printer
  77. ; is organized vertically, this program prints the screen image rotated 90
  78. ; degrees.
  79.  
  80.     SUBTTL    Entry Point
  81.     PAGE    +
  82.  
  83. cseg    segment
  84.     assume    cs:cseg,ds:cseg
  85.  
  86. ; This is the initial program entry point. It jumps to 'init' which sets
  87. ; up the interrupt vector, prints out a message confirming program load,
  88. ; and does a terminate and stay resident call.
  89.  
  90.     jmp    init    ; jump around real code to load in memory
  91.     SUBTTL    PrtSc Entry Point
  92.     PAGE    +
  93.  
  94. ; This is the entry point when PrtSc is pressed. It is ORG'ed at location
  95. ; 348 (minus 100h) to allow the previous 348 bytes, including the now
  96. ; unnecessary PSP to be used as a buffer to hold a full vertical scan of the
  97. ; screen. 
  98.  
  99.     org    348-100h
  100.  
  101. int5:
  102.     push    ax
  103.     push    bx
  104.     push    dx
  105.  
  106. ; First we must determine whether the Hercules board is in text mode or
  107. ; graphics mode. This is done with a program given to me by Hercules Computer
  108. ; Technology Inc. It isn't real clear to me why this program works the way it
  109. ; does, but it appears that if you force trip the light pen, it returns the
  110. ; character location (6845 meaning) just past the end of the screen. This may
  111. ; have something to do with the fact that there is no light pen receiving a
  112. ; raster pulse. If this is the case, I have no idea if this still works if you
  113. ; actually have a light pen connected.
  114.  
  115. ourstat    equ    03bah
  116. notvsync equ    80h
  117. lpreset    equ    03bbh
  118. lpset    equ    03b9h
  119. our6845    equ    03b4h
  120. threshold equ    (80*25 + 45*87)/2
  121.  
  122.     mov    dx,ourstat
  123.  
  124. w1:    in    al,dx        ; first, wait for vertical retrace
  125.     test    al,notvsync
  126.     jz    w1
  127.  
  128. w2:    in    al,dx        ; then make sure not to test during vertical
  129.     test    al,notvsync    ; retrace
  130.     jnz    w2
  131.  
  132.     xor    al,al        ; tickle light pen
  133.     mov    dx,lpreset
  134.     out    dx,al
  135.     mov    dx,lpset
  136.     out    dx,al
  137.  
  138.     mov    al,16        ; get high byte of lp trip offset
  139.     mov    dx,our6845
  140.     out    dx,al
  141.     inc    dx
  142.     in    al,dx
  143.     mov    bh,al
  144.  
  145.     mov    al,17        ; and low byte
  146.     mov    dx,our6845
  147.     out    dx,al
  148.     inc    dx
  149.     in    al,dx
  150.  
  151.     mov    ah,bh        ; return light pen trip address
  152.     cmp    ax,threshold
  153.     pop    dx        ; restore original user registers
  154.     pop    bx
  155.     pop    ax
  156.     ja    gprint        ; above threshold, in graphics mode
  157.  
  158. ; The following two lines are a 'jmp far' instruction to jump to the BIOS
  159. ; print screen routine if the Hercules board is in text mode. The location
  160. ; is filled in in the 'init' routine.
  161.  
  162. tjump:    db    0eah        ;! JMP FAR 0:0
  163.     dw    0,0
  164.  
  165.     SUBTTL    Graphics Entry Point
  166.     PAGE    +
  167.  
  168. ; This is the entry point if the Hercules board is in graphics mode.
  169.  
  170. gprint:
  171.     push    ax        ; save all registers
  172.     push    bx
  173.     push    cx
  174.     push    dx
  175.     push    si
  176.     push    di
  177.     push    bp
  178.     push    ds
  179.     push    es
  180.  
  181. ; First test location 50:0 to see if print screen is already in progress.
  182.  
  183.     mov    ax,50h
  184.     mov    ds,ax
  185.     cmp    byte ptr ds:0,1    ; prtsc already active?
  186.     mov    byte ptr ds:0,1    ; it is now
  187.     mov    ax,cs        ; retore ds:
  188.     mov    ds,ax
  189.     jnz    gp1        ; print screen in progress before? no.
  190.     jmp    exit        ; yes
  191.  
  192. ; (B.R. Fix) Uncomment the lines marked 'X' below to restore page 
  193. ; selection capability
  194. gp1:
  195.     xor    ax,ax        ; set for read char
  196.     int    16h        ; read char from keyboard
  197.     mov    dx,0b000h    ; assume page 1
  198.     cmp    al,'1'
  199.     je    gp3
  200.     mov    dx,0b800h    ; page 2
  201.     cmp    al,'2'
  202.     je    gp3
  203.  
  204. ; neither '1' nor '2', so beep an error and return
  205.  
  206. timer    equ    40h
  207. port_b    equ    61h
  208.  
  209.     mov    al,10110110b    ; sel tim 2,lsb,msb,binary
  210.     out    timer+3,al    ; write the timer mode reg
  211.     mov    ax,533h        ; divisor for 1000 hz
  212.     out    timer+2,al    ; write timer 2 cnt - lsb
  213.     mov    al,ah
  214.     out    timer+2,al    ; write timer 2 cnt - msb
  215.     in    al,port_b    ; get current setting of port
  216.     mov    ah,al        ; save that setting
  217.     or    al,03        ; turn speaker on
  218.     out    port_b,al
  219.     sub    cx,cx        ; set count to 500 ms
  220. gp2:    loop    gp2        ; delay before turning off
  221.     mov    al,ah        ; recover value of port
  222.     out    port_b,al
  223.     jmp    done    
  224.  
  225. ;
  226. ; set up printer for graphics printing
  227. ;
  228. gp3:    mov    ds,dx        ; segment address of page requested
  229.     push    cs        ; es points to work area which is at
  230.     pop    es        ;  beginning of code segment
  231.     xor    dx,dx        ; printer number is zero (LPT1)
  232.     xor    si,si        ; horizontal offset (start at left edge)
  233.  
  234.     mov    ax,27        ; select 8/72" line feeds (ESC A 8)
  235.     int    17h
  236.     mov    ax,'A'
  237.     int    17h
  238.     mov    ax,8
  239.     int    17h
  240.  
  241. ;(B.R. Fix) BUG! These lines set the printer back to normal line feeds,
  242. ;undoing the work done in the last block. 
  243. ;    mov    ax,27        ; set selection in force (ESC 2)
  244. ;    int    17h
  245. ;    mov    ax,'2'
  246. ;    int    17h
  247.  
  248. ; start running through screen starting with lower left corner, working up
  249. ; and then to the right
  250. ;
  251. ; l1 is loop for each vertical pass. This is also one print line.
  252.  
  253. l1:    mov    bx,1e3ch    ; bottom-most scan line in first quadrant
  254.     mov    cx,87        ; # horizontal lines in a quadrant (348/4)
  255.        xor    di,di        ; pointer into ES: work area (beginning of code)
  256.  
  257. l2:    mov    al,6000h[bx+si]    ; get character from quadrant 4 scan line
  258.     stosb            ; and store in work area
  259.     cmp    al,0        ; if it was other than a zero, store new
  260.     je    $+4        ; of di in dx so dx will be length of line to
  261.     mov    dx,di        ; print (null truncated)
  262.  
  263.     mov    al,4000h[bx+si]    ; do likewise for third quadrant
  264.     stosb
  265.     cmp    al,0
  266.     je    $+4
  267.     mov    dx,di
  268.  
  269.     mov    al,2000h[bx+si]    ; and second
  270.     stosb
  271.     cmp    al,0
  272.     je    $+4
  273.     mov    dx,di
  274.  
  275.     mov    al,[bx+si]    ; and the first quadrant
  276.     stosb
  277.     cmp    al,0
  278.     je    $+4
  279.     mov    dx,di
  280.  
  281.     sub    bx,5ah        ; up one horizontal scan line (90 bytes)
  282.     loop    l2        ;  (effectively 4 horizontal scan lines)
  283.  
  284.     cmp    dx,0        ; completely blank vertical line?
  285.     je    l5        ; don't print, just advance paper
  286.     push    dx        ; save length of line to print
  287.     xor    dx,dx        ; for printer zero, again
  288.     mov    cx,10        ; count for left margin (ie, 10 spaces)
  289. l3:    mov    ax,' '        ; the print them
  290.     int    17h
  291.     loop    l3
  292.     mov    ax,27        ; then print the graphics line
  293.     int    17h        
  294.     mov    ax,'L'        ; ESC L introduction (double density)
  295.     int    17h
  296.     pop    cx        ; length of line to print
  297.     shl    cx,1        ; *2 since we print double for double density
  298.     mov    ax,cx
  299.     xor    ah,ah        ; get least significant byte
  300.     int    17h        ; and send it
  301.     xor    ah,ah
  302.     mov    al,ch        ; then get most significant byte
  303.     int    17h        ; and send it
  304.     shr    cx,1        ; then shift back down to real count
  305.  
  306.     push    si        ; save horizontal offset
  307.     xor    si,si        ; point to save graphics line
  308. l4:    lods    byte ptr cs:0    ; get a character to print
  309.     xor    ah,ah
  310.     push    ax        ; BUG: my clone BIOS' int 17 stomps on AL
  311.     int    17h        ; and print it
  312.     pop    ax        ; restore due to my BIOS' bug
  313.     int    17h        ; print a second time for increased density
  314.     loop    l4        ; till end of line
  315.     pop    si        ; and restore horizontal offset for next pass
  316.  
  317. l5:    mov    ax,0dh        ; now do a CRLF
  318.     int    17h
  319.     mov    ax,0ah
  320.     int    17h
  321.     
  322.     inc    si        ; move one space to the right
  323.     cmp    si,5ah        ; already on right hand edge?
  324.     jae    l6        ; yes
  325.     jmp    l1        ; no, do another vertical pass
  326. l6:
  327.     
  328.     mov    ax,27        ; set the printer back to 6lpi
  329.     int    17h        ;  (even if it was at 8lpi)
  330.     mov    ax,'2'
  331.     int    17h
  332.     mov    ax,12        ; really 12/72 of an inch
  333.     int    17h
  334.  
  335. done:    mov    ax,50h
  336.     mov    ds,ax
  337.     mov    byte ptr ds:0,0    ; prtsc is now over
  338.  
  339. exit:
  340.     pop    es        ; restore all registers
  341.     pop    ds
  342.     pop    bp
  343.     pop    di
  344.     pop    si
  345.     pop    dx
  346.     pop    cx
  347.     pop    bx
  348.     pop    ax
  349.  
  350.     iret            ; and return to what user was doing
  351.     SUBTTL    Initial Entry Point (Setup)
  352.     PAGE    +
  353. ; This is the code executed the first time the program is invoked. It first
  354. ; builds a jump instruction at location 'tjump' that jumps to the BIOS print
  355. ; screen routine when the Hercules board is in text mode. Then it loads the
  356. ; print screen vector to point to the entry point and issues a terminate and
  357. ; stay resident call.
  358.  
  359. init:
  360.     mov    ax,ds:2ch
  361.     mov    es,ax        ; segment address of environment strings
  362.     mov    ah,49h        ; deallocate our copy of environment strings
  363.     int    21h
  364.     mov    ax,3505h        ; get address for normal print screen
  365.     int    21h
  366.     mov    ax,es
  367.     mov    word ptr tjump+103h,ax    ; store segment address in jmp instr.
  368.     mov    word ptr tjump+101h,bx    ; likewise with offset
  369.  
  370.     mov    dx,offset int5+100h
  371.     mov    ax,2505h        ; grab print screen interrupt vector
  372.     int    21h
  373.  
  374.     mov    dx,offset announce+100h
  375.     mov    ah,09h            ; print announcement
  376.     int    21h
  377.     mov    dx,offset init+100h    ; lock program in memory
  378.     int    27h
  379.  
  380. announce:
  381.     db    0dh,0ah,'HPrtSc - Graphics Screen Dump, Version 1.00',0dh,0ah
  382.     db    'Copyright (c) 1987, Background Processes',0dh,0ah,'$'
  383.  
  384. cseg    ends
  385.     end
  386.